home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 22 / CU Amiga Magazine's Super CD-ROM 22 (1998)(EMAP Images)(GB)[!][issue 1998-05].iso / PowerPC / Programming / PPCsiod / sources / vector.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-22  |  3.6 KB  |  121 lines

  1. /* Scheme In One Define.
  2.  
  3. The garbage collector, the name and other parts of this program are
  4.  
  5.  *                     COPYRIGHT (c) 1989 BY                              *
  6.  *      PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS.       *
  7.  
  8. Conversion  to  full scheme standard, characters, vectors, ports, complex &
  9. rational numbers, and other major enhancments by
  10.  
  11.  *      Scaglione Ermanno, v. Pirinoli 16 IMPERIA P.M. 18100 ITALY        * 
  12.  
  13. Permission  to use, copy, modify, distribute and sell this software and its
  14. documentation  for  any purpose and without fee is hereby granted, provided
  15. that  the  above  copyright  notice appear in all copies and that both that
  16. copyright   notice   and   this  permission  notice  appear  in  supporting
  17. documentation,  and that the name of Paradigm Associates Inc not be used in
  18. advertising or publicity pertaining to distribution of the software without
  19. specific, written prior permission.
  20.  
  21. PARADIGM  DISCLAIMS  ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  22. ALL  IMPLIED  WARRANTIES  OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  23. PARADIGM  BE  LIABLE  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  24. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  25. IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  26. OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <ctype.h>
  33. #include <setjmp.h>
  34. #include <signal.h>
  35. #include <math.h>
  36.  
  37. #include "siod.h"
  38.  
  39. LISP vectorcons(long length,LISP init)
  40. {long flag,i;
  41.  LISP s,f,*t;
  42.  t=NULL;
  43.  flag = no_interrupt(1); 
  44.  if(length>0)
  45.    t = (LISP *)must_malloc(length * sizeof(LISP));
  46.  NEWCELL(s,tc_vector);
  47.  VECTOR(s) = t;
  48.  VECSIZE(s) = length;
  49.  for(i=0;i<length;i++)
  50.    VECTOR(s)[i] = init;
  51.  no_interrupt(flag);
  52.  return(s);}
  53.  
  54. LISP listtovector(LISP lis)
  55. {LISP res,l;
  56.  unsigned int n;
  57.  l=lis;
  58.  if(NCONSP(lis)&&NNULLP(lis)) err("list->vector",lis,ERR_GEN_ARG | ERR_NPAI);
  59.  for(n=0;CONSP(l);n++)
  60.   l=cdr(l);
  61.  res = vectorcons(n,NIL);
  62.  l=lis;
  63.  for(n=0;CONSP(l);n++)
  64.    {VECTOR(res)[n] = car(l);
  65.    l=cdr(l);}
  66.  return(res);}
  67.  
  68. LISP vectortolist(LISP vec)
  69. {LISP res;
  70.  int n;
  71.  if(NVECTORP(vec)) err("vector->list",vec,ERR_GEN_ARG | ERR_NVEC);
  72.  res= NIL;
  73.  for(n = (VECSIZE(vec))-1;n>=0;n--)
  74.   res = cons(VECTOR(vec)[n],res);
  75.  return(res);}
  76.  
  77. LISP vectorm(LISP args)
  78. {LISP res;
  79.  return(listtovector(args));}
  80.  
  81. LISP makevector(LISP size,LISP init)
  82. {LISP vec;
  83.  if(NINTNUMP(size)) err("make-vector",size,ERR_FIRST | ERR_NINT);
  84.  vec = vectorcons(INTNM(size),init);
  85.  return(vec);}
  86.  
  87. LISP vectorset(LISP vec,LISP index,LISP value)
  88. {if(NVECTORP(vec)) err("vector-set!",vec,ERR_FIRST | ERR_NVEC);
  89.  if(NINTNUMP(index)) err("vector-set!",index,ERR_SECOND | ERR_NINT);
  90.  if((INTNM(index) < 0) || (INTNM(index)+1) > VECSIZE(vec)) 
  91.        err("vector-set!",index,ERR_SECOND | ERR_IND_RAN);
  92.  VECTOR(vec)[INTNM(index)] = value;
  93.  return(vec);}
  94.  
  95. LISP vectorfill(LISP vec,LISP value)
  96. {int i,size;
  97.  if(NVECTORP(vec)) err("vector-fill!",vec,ERR_FIRST | ERR_NVEC);
  98.  size = VECSIZE(vec);
  99.  for(i=0;i<size;i++)
  100.     VECTOR(vec)[i] = value;
  101.  return(vec);}
  102.  
  103. LISP vectorref(LISP vec,LISP index)
  104. {if(NVECTORP(vec)) err("vector-ref",vec,ERR_FIRST | ERR_NVEC);
  105.  if(NINTNUMP(index)) err("vector-ref",index,ERR_SECOND | ERR_NINT);
  106.  if((INTNM(index) < 0) || (INTNM(index)+1) > VECSIZE(vec)) 
  107.        err("vector-ref",index,ERR_SECOND | ERR_IND_RAN);
  108.  return(VECTOR(vec)[INTNM(index)]);}
  109.  
  110. LISP vectorlenght(LISP vec)
  111. {LISP res;
  112.  if(NVECTORP(vec)) err("vector-length",vec,ERR_GEN_ARG | ERR_NVEC);
  113.  res=intcons(VECSIZE(vec));
  114.  return(res);}
  115.  
  116. LISP vectorp(LISP vec)
  117. {if(VECTORP(vec))
  118.    return(truth);
  119.  else
  120.    return(NIL);}
  121.